/* This code reads the PCM1808 and sends the data to a PC. The fastest you can sample is 16 kHz using this ASCII way of encoding the data, but shows that with some encoding you could sample at up to 96 kHz. */ #include <I2S.h> #define RATE 16000 #define MCLK_MULT 256 // 384 for 48 BCK per frame, 256 for 64 BCK per frame I2S i2s(INPUT); void setup() { Serial.begin(); i2s.setDATA(2); // These are the pins for the SDR-TRX. i2s.setBCLK(0); i2s.setMCLK(3); // Note: LRCK pin is BCK pin plus 1 (1 in this case). i2s.setBitsPerSample(24); i2s.setFrequency(RATE); i2s.setMCLKmult(MCLK_MULT); i2s.setSysClk(RATE); i2s.setBuffers(32,0,0); i2s.begin(); } void loop() { static int32_t r, l; i2s.read32(&l, &r); // The shift by 9 bits is unexpected... Eight is what I expect. Serial.printf("%d %d \r\n", l<<9, r<<9); // This only works up 16 kHz. // With the extra four spaces it should wark at 96 kHz with 16 bit samples // and leaving about 90 frames for control packets if we can figure out how // to do that. }
#include <Arduino.h> #include <I2S.h> I2S i2s(INPUT); #define N 1 #define RATE 8000 int32_t r[N], l[N]; void setup() { Serial.begin(); i2s.setDATA(2); i2s.setBCLK(0); i2s.setMCLK(3); // Note: LRCK pin is BCK pin plus 1 (1 in this case). i2s.setBitsPerSample(24); i2s.setFrequency(RATE); i2s.setMCLKmult(384); i2s.setSysClk(RATE); i2s.setBuffers(64,16,0); i2s.begin(); } void loop() { int i; int32_t left_plus_right, left_minus_right; for(i=0; i
# This was to try and get both the Si5351 and the INA219 working together. #include <Wire.h> #include <Adafruit_INA219.h> #include "si5351.h" #include "Wire.h" Si5351 si5351; Adafruit_INA219 ina219; void setup(void) { bool i2c_found; Serial.begin(115200); while (!Serial) { // will pause Zero, Leonardo, etc until serial console opens delay(1); } i2c_found = si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); if(!i2c_found) { Serial.println("Device not found on I2C bus!"); } // Set CLK2 to output 14.074 MHz si5351.set_freq(1407400000ULL, SI5351_CLK2); Serial.println("Hello!"); // Initialize the INA219. // By default the initialization will use the largest range (32V, 2A). However // you can call a setCalibration function to change this range (see comments). if (! ina219.begin()) { Serial.println("Failed to find INA219 chip"); while (1) { delay(10); } } // To use a slightly lower 32V, 1A range (higher precision on amps): //ina219.setCalibration_32V_1A(); // Or to use a lower 16V, 400mA range (higher precision on volts and amps): ina219.setCalibration_16V_400mA(); Serial.println("Measuring voltage and current with INA219 ..."); } void loop(void) { float shuntvoltage = 0; float busvoltage = 0; float current_mA = 0; float loadvoltage = 0; float power_mW = 0; shuntvoltage = ina219.getShuntVoltage_mV(); busvoltage = ina219.getBusVoltage_V(); current_mA = ina219.getCurrent_mA(); power_mW = ina219.getPower_mW(); loadvoltage = busvoltage + (shuntvoltage / 1000); Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V"); Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV"); Serial.print("Load Voltage: "); Serial.print(loadvoltage); Serial.println(" V"); Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA"); Serial.print("Power: "); Serial.print(power_mW); Serial.println(" mW"); Serial.println(""); delay(2000); }